package edu.nf.project.mappers.storeOperation.convention;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.nf.project.entitys.entity.storeOperation.convention.cargo.Cargo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CargoMapper extends BaseMapper<Cargo> {

    /**
     * 查询系统中所有货物（食材）及其库存数量等信息。
     * 这些数据用于构建当前可用库存的模拟环境。
     * @return 所有货物（食材）列表
     */
    @Select("SELECT * FROM cargo")
    List<Cargo> findAll();


    @Select({
            "<script>",
            "SELECT * FROM cargo",
            "WHERE cargo_id IN",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    List<Cargo> selectByIds(@Param("ids") List<Integer> ids);

    @Update("UPDATE cargo SET stock_quantity = stock_quantity - #{quantity} WHERE cargo_id = #{cargoId}")
    void decreaseStock(@Param("cargoId") Integer cargoId, @Param("quantity") Integer quantity);


}
